Alibabacloud.com offers a wide variety of articles about log4j conversionpattern example, easily find your log4j conversionpattern example information here online.
Spring uses log4j, and there are 2 ways to do it.1. Do not make any configuration in Web. Xml.Log4j.properties placed in the Classpath root directory,The resulting log file does not have a relative path, and if a relative path is written, it is generated under the root path of the installation tomcat.2. Set in Web. Xml.Printing parameters: log4j Format the log information in a print format similar to the pr
Log4j-1.2.16.ja environment: myeclipse10 + log4j1.2.16 + jdk1.6
1. Create a Java project named log4jtest.
2. SetLog4j-1.2.16.jar copy to project root directory, right-click Project, properties, Java build path, add jars, selectLog4j-1.2.16.jar
3. InSource codeDirectory to create an XML file: log4j. xml. The configuration starts. The content is as follows:
XML version = "1.0" encoding = "UTF-8"
Example of how MyBatis3 outputs SQL using log4j on the console, mybatis3log4j
Why do I need to output SQL statements on the console?
Of course, it is convenient for development and debugging.
If a database-related operation encounters a problem, we can quickly troubleshoot the problem based on the output SQL statement.
Output Information:
[Org. mybatis. spring. SqlSessionUtils]-Creating a new SqlSession[O
With log4j, you can easily process logs in your project-control the destination of the Log information output (console, file, GUI component, or NT Event recorder), control the output format of each log (htmllayout layout format, patternlayout layout format, Simplelayout layout format or ttcclayout), controls the level of output log information (debug level, info level, warn level, error level, or fatal level), and so on. Here's a simple
steps:
Create a new Java project and import the log4j jar package;
Create the Log4j.properties profile and set it in the SRC directory;1 # Set the global output level2Log4j.rootlogger=Error,stdout,file3 4 # Output logs above the error level to the console5log4j.appender.stdout=Org.apache.log4j.ConsoleAppender6log4j.appender.stdout.target=System.out7log4j.appender.stdout.layout=Org.apache.log4j.PatternLayout8Log4j.appender.stdout.layout.conversio
preceding outputs and shields all the subsequent outputs. Here, we recommend two types: Error: only error information is recorded; debug: detailed information of all errors is recorded. In the production configuration, disable the "apply to console" option and only enable file). The following two consoles and files represent the location of log output, and the following two can be named at will, to be clear and easy to understand, you can use words with a glance. For
I have not written examples in the log4j usage notes. In this article, I will write a complete application instance of log4j.
In the log4j usage notes, we already know that the same log information can be output to multiple output destinations at the same time. In the following example, I will demonstrate how to output
Here is an example of file pointing to a specific file instead of a folder.
### Set output encoding ###Log4j. appender. logfile. Encoding = UTF-8### Set log levels ###Log4j. rootlogger = debug, stdout, d, e
### Out print at console ###Log4j. appender. stdout = org. Apache. log4j
The log frameworks available for MyBatis include SLF4J, Apache Commons Logging, Log4J, and JDK logging. This article will transform the previous example to demonstrate the simple use of Log4J source code: http://down.51cto.com/data/521820. This source code corresponds to the fifth case of the following content ).
First, copy the related
: log4j.apache.mylogger=warn-Log4j.apache.mylogger.mysonlogger=,file In the above code, Mysonlogger is the subclass logger component of MyLogger. 6. Specify the log level in the package unit Log4j.logger.com.neareast =debugLog4j.logger.org.apache.struts=warnSpecifies that all classes under the Com.neareast package are rated as Debug.Specifies that all classes under the Struts package are rated warn. 7. Basic Use Method usually there are two ways to use it:1. Use Org.apache.commons.logging.Log cl
Log4j is really simple, simple to the point of outrageous. Not to log it. So I'll give you a log, and then you can write something with log, and first come to a complete class example:
Package test;
import Org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Public class Test {
Static Log log = Logfactory.getlog (Test.class);
Public void log () {
Log.debug ("Debug Info.");
Log.inf
First need to download log4j package, the current use of the most is still log4j 1.2, although Log4j 2 has been released, Log4j 1.2: http://logging.apache.org/log4j/1.2/download.htmlDownload complete decompression, log4j is a very
the time, thread, category, and so on that the log produced) Log4j.appender.a.layout=Org.apache.log4j.SimpleLayoutlog4j.appender.logfile=org.apache.log4j.fileappender# The address of the settings file Log4j.appender.logfile.File=Mylog.loglog4j.appender.logfile.layout=org.apache.log4j.patternlayout# sets the style for patternlayout. #%the message specified in the M output code #%P-Output priority, i.e. Debug,info,warn,error,fatal #%r output The number of milliseconds to output the log informatio
Objective:The author has been in the System.out in the log, because the author most of the time is written in the Tomcat container running some small web applications, so it seems that there is no problem: the printed log can be found in the Tomcat's own log directory in some of the logs. However, the author recently contacted a project, need to write a non-dependent on the container can directly run on the system socket server program, so that I need a can hit their own log of the place, so beg
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.